﻿using AutoMapper;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.WriteAPI.Application.Images
{
    public class ImageAddRequestHandler : IRequestHandler<ImageAddRequestModel, APIResult>
    {
        private readonly IBaseRepository<Image> imageRepository;
        private readonly IMapper mapper;
        public ImageAddRequestHandler(IBaseRepository<Image> imageRepository, IMapper mapper)
        {
            this.imageRepository = imageRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(ImageAddRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.AddSuccess;
            result.Msg = "新增成功";

            Image images = mapper.Map<Image>(request);
            imageRepository.Add(images);

            return Task.FromResult(result);
        }
    }
    public class ImageAddRequestModel:IRequest<APIResult>
    {
        /// <summary>
        /// 商品编号
        /// </summary>
        public string ProductCode { get; set; }
        /// <summary>
        /// 溯源类型
        /// </summary>
        public int TraceType { get; set; }
        /// <summary>
        /// 图片类型
        /// </summary>
        public int ImgType { get; set; }
        /// <summary>
        /// 图片地址
        /// </summary>
        public string Url { get; set; }
    }
}
